package md.mru.backend.core.service;

import md.mru.backend.common.BaseDtoMapper;
import md.mru.backend.core.domains.Folder;
import md.mru.backend.core.dtos.FolderDto;
import md.mru.backend.core.repositories.FolderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author sergiu.marin
 * @since 01.04.2014
 */
//@Transactional
@Service
public class FolderService {

    @Autowired
    @Qualifier(value = "dtoMapper")
    private BaseDtoMapper mapper;
    @Autowired
    private FolderRepository folderRepository;
    private List<FolderDto> folders;


    public void save(FolderDto folderDto) {
        Folder folder = mapper.map(folderDto, Folder.class);
        folderRepository.save(folder);
    }

    public List<FolderDto> getFolders() {
        List<Folder> folders = folderRepository.findAll();
        return mapper.mapList(folders, FolderDto.class);
    }

    public FolderDto getFolder(long folderId) {
        Folder folder = folderRepository.findOne(folderId);
        return mapper.map(folder, FolderDto.class);
    }
}
